package com.wlyuan.open.scanner.application.handler.incr;

import com.wlyuan.open.dto.OpenRelationSyncDTO;
import com.wlyuan.open.scanner.assembler.ScannerRelationAssembler;
import com.wlyuan.open.scanner.constant.ScannerCodeEnum;
import com.wlyuan.open.scanner.repository.RelationRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author lijing
 * @description 客户与承运方邀请关系 增量listener
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class CustomerRelationIncrHandler extends BaseIncrHandler<OpenRelationSyncDTO> {
    private final RelationRepository relationRepository;

    /**
     * 单个增量同步
     *
     * @param customerId
     */
    @Override
    public OpenRelationSyncDTO process(Long customerId) {
        logger.info("客户与承运方邀请关系增量同步：{}", customerId);
        return Optional.ofNullable(customerId).map(id -> {
            var source = relationRepository.getRelationByCustomerId(id);
            return ScannerRelationAssembler.assemble(source);
        }).orElse(null);
    }

    @Override
    public void incrByTenantId(Long tenantId) {
        relationRepository.getRelationByTenantId(tenantId);
    }

    @Override
    public void incrByTime(Long tenantId, String startTime, String endTime) {

    }

    @Override
    public String getSyncType() {
        return ScannerCodeEnum.RELATION.getVal();
    }
}
